<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加菜品</title>
    <style>
        div {
            position: absolute;
            top: 30%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }

        table, tr, th, td {
            border: 1px solid #5fbdcb;
        }

        table {
            border-collapse: collapse;
        }
    </style>
</head>
<body>
<div>
    <form id="form" action="${pageContext.request.contextPath}/dish.do?method=add" method="post" enctype="multipart/form-data">
        <label for="storeId"></label><input type="text" id="storeId" name="storeId" hidden>
        <label for="method"></label><input type="text" id="method" name="method" value="add" hidden>
        <label for="dishName">菜品名：</label>
        <input type="text" name="dishName" id="dishName" placeholder="请输入菜品名"><br>
        <label for="price">价格：</label>
        <input type="number" name="price" id="price" step="0.01" placeholder="请输入价格" min="0"><br>
        <label for="describe">描述：</label>
        <input type="text" name="describe" id="describe" placeholder="请输入描述"><br>
        菜品照片：<input type="file" name="photo" id="photo"><br>
        <input type="file" hidden>
        <input type="submit">
        <a id="a">返回</a>
    </form>
</div>
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script>
    function getParam(url, name) {
        try {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = url.split('?')[1].match(reg);
            if (r != null) {
                return r[2];
            }
            return "";
        } catch (e) {
            return "";
        }
    }

    let url = window.location.href;
    let storeId = getParam(url, 'storeId');
    console.log(storeId);
    let selector = document.querySelector("#storeId");
    selector.value = storeId;
    console.log(selector.value);
    console.log(document.querySelector('#method').value);
    $(function () {
        let a = document.querySelector('a');
        a.href = 'SellerDishPage.jsp?storeId=' + storeId;
    })

</script>
</body>
</html>
